<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script src="node_modules/jquery/dist/jquery.js"></script>
  <script>
    // $.ajax({
    //   url: 'http://liufusong.top:4000/books',
    //   success: function (res) {
    //     console.log(res)
    //     const id = res[0]
    //     console.log(id)
    //     $.ajax({
    //       url: 'http://liufusong.top:4000/books/' + id,
    //       success: function (res2) {
    //         console.log(res2)
    //       }
    //     })
    //   }
    // })

    const axios = (options) => {
      return new Promise(function(resolve, reject) {
        // 回调函数内部进行异步处理
        $.ajax({
          url: options.url,
          type: options.type || 'GET',
          success: function (res) {
            resolve(res)
          },
          error: function (err) {
            reject(err)
          }
        })
      })
    }
    
    const getBooksRes1 = axios({
      url: 'http://liufusong.top:4000/books/1'
    }).then((res) => {
      console.log(res)
      return axios({
        url: 'http://liufusong.top:4000/books/2'
      })
    }).then(res => {
      console.log(res)
      return axios({
        url: 'http://liufusong.top:4000/books/3'
      })
    })

  </script>
</body>
</html>